package com.jcl.recruit.console.mapper.provider;

import com.jcl.recruit.console.model.ConsoleDbCorp;
import com.jcl.recruit.mapper.provider.SqlProvider;

import static org.apache.ibatis.jdbc.SqlBuilder.*;

/**
 * @ClassName ConsoleCorpInfoProvider

 * @Author yyliu
 * @Date 2018/12/13 16:54
 * @Version 1.0
 **/
public class ConsoleDbCorpProvider implements SqlProvider<ConsoleDbCorp> {

    private static final String TABLE_NAME = "t_console_db_corp";

    public String insert(ConsoleDbCorp entity) {
        BEGIN();
        INSERT_INTO(TABLE_NAME);
        if (entity.getCorpCode() != null) {
            VALUES("corp_code", "#{corpCode,jdbcType=VARCHAR}");
        }

        if (entity.getServerName() != null) {
            VALUES("server_name", "#{serverName,jdbcType=VARCHAR}");
        }

        if (entity.getStatus() != null) {
            VALUES("status", "#{status,jdbcType=INTEGER}");
        }

        if (entity.getCreateTime() != null) {
            VALUES("create_time", "#{createTime,jdbcType=TIMESTAMP}");
        }

        if (entity.getUpdateTime() != null) {
            VALUES("update_time", "#{updateTime,jdbcType=TIMESTAMP}");
        }

        return SQL();
    }

    public String updateByPrimaryKey(ConsoleDbCorp entity) {
        BEGIN();
        UPDATE(TABLE_NAME);

        if (entity.getCorpCode() != null) {
            SET("corp_code = #{fullName,jdbcType=VARCHAR}");
        }

        if (entity.getServerName() != null) {
            SET("server_name = #{shortName,jdbcType=VARCHAR}");
        }

        if (entity.getStatus() != null) {
            SET("status = #{mealPackage,jdbcType=INTEGER}");
        }

        if (entity.getUpdateTime() != null) {
            SET("update_time = #{updateTime,jdbcType=TIMESTAMP}");
        }

        WHERE("id = #{id,jdbcType=INTEGER}");

        return SQL();
    }

}
